/**
 * 
 */
package com.org.javabody.IndexOf.SimpleIndexOf;

import java.util.regex.Pattern;

/**

 * @author Administrator

 *

 */
public class SimpleIndexOf {

	private static String getStr(String str, int n) {
        int i = 0;
        int s = 0;
        while (i++ < n) {
            s = str.indexOf("4001~|~", s + 1);
            if (s == -1) {
                return str;
            }
        }
        return str.substring(0, s);
    }
	
	/**

	 * @param args

	 */
	public static void main(String[] args) {
		String str = "[文件头]|记录数|应征金额|共：43条记录|金额合计：￥15050.000000元[文件明细]"+
"4001~|~201603170638332200001~|~100000000000250426~|~2040~|~330302195211120810~|~03~|~1~|~90009092~|~201512~|~14~|~350.00~|~322~|~20160317~|~20160317~|~"+
"4001~|~201603170638332200002~|~100000000000251221~|~2040~|~330302195403314038~|~03~|~1~|~90019164~|~201512~|~14~|~350.00~|~322~|~20160317~|~20160317~|~"+
"4001~|~201603170638332200003~|~100000000000252401~|~2040~|~330302195702244826~|~03~|~1~|~90035834~|~201512~|~14~|~350.00~|~322~|~20160317~|~20160317~|~";
		int a = str.indexOf("共：");
        int b = str.indexOf("条");
        String x = "";
        if((a!=-1)&&(b!=-1)) {
        	 x = str.substring(a+2, b);
        }
       int o = str.indexOf("￥");
       int p = str.indexOf("元");
       String y = "";
       if((o!=-1)&&(p!=-1)) {
    	   y = str.substring(o+1, p);
       }
       
       System.out.println(x);
       System.out.println(y);
       int q = str.indexOf("4001");
       String sql = str.substring(q, str.length());
       System.out.println(sql);
       
       if(sql.startsWith("4001")) {
    	   Pattern pat = Pattern.compile("4001");//预编译Pattern

    	   String[] s = pat.split(sql);
    	   for(int i = 0; i <s.length; i++) {
    		   if(i>=1){
    			   String t =  "4001"+s[i];
    			   String hql = t.replace("~|~", ";");
    			   System.out.println(hql);
    			   Pattern patt = Pattern.compile(";");//预编译Pattern

    	    	   String[] s1 = patt.split(hql);
    	    	   for(int j = 0; j <s1.length; j++) {
    	    		   System.out.println(s1[j]);
    	    	   }
    		   }
    	   }	 
       }     
	}

}